export default class BoxRotateScript extends Laya.Script3D {

    constructor() { 
        super();
        this.rotation= new Laya.Quaternion();
        this.position=new Laya.Vector3();
        this.sub=new Laya.Vector3();
        this.cameraPosition=new Laya.Vector3();
        
    }
    onAwake(){
        this.camera=this.owner.scene.getChildByName("Main Camera");
        Laya.Vector3.subtract(this.camera.transform.position,this.owner.transform.position,this.sub);
        
    }

    onUpdate(state){
        this.camera.transform.rotate(new Laya.Vector3(0,1,0),true,false);
        this.rotation=this.camera.transform.rotation; 
        Laya.Vector3.transformQuat(this.sub,this.rotation,this.position);
        Laya.Vector3.add(this.position,this.owner.transform.position,this.cameraPosition);
        this.camera.transform.position=this.cameraPosition;  
        
    }
    
    onEnable() {
    }

    onDisable() {
    }
}